# -*- coding: utf-8 -*-
"""
@Version : 
@Author  : ChenMZ
@Time    : 2025/09/16
@File    : MainUIView.py
@Desc    : 主界面
@Modify  : 
"""
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QSize
from qfluentwidgets import (FluentWindow, NavigationItemPosition)
from typing import (Dict, Union, List)
from ui.MainUI import Ui_MainWindow
from device import DevGroups
from tool.global_func import svg_to_pixmap, ColorTheme, DevIcon
from view.DevMonitorUIView.MonitorUIView import DevMonitorView


class MainView(FluentWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.theme = "light"
        self.monitor: Dict[str, Dict[str, DevMonitorView]] = {}

        self.initialization()
        self.resize(*[x / 2 for x in self.screen_size()])

    @staticmethod
    def screen_size():
        import ctypes
        user32 = ctypes.windll.user32
        # 单显示器屏幕宽度和高度:
        return user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)

    def initialization(self):
        self.setWindowTitle("PCMonitor")
        self.setWindowIcon(
            QIcon(svg_to_pixmap(":/window/icons/title.svg", 600, 600, ColorTheme.light_theme))
        )
        self.init_navigation()

    def init_navigation(self):
        self.navigationInterface.setAcrylicEnabled(True)  # 亚克力效果
        self.navigationInterface.setMinimumWidth(300)
        for dev_name, dev_group in DevGroups.members().items():
            dev_view = DevIcon.members()[dev_name]
            self.monitor[dev_group.group_name] = {}
            try:
                for _, dev in enumerate(dev_group.dev_client):
                    dev_name = "{} {}".format(dev_view.tr_zh, _)
                    self.monitor[dev_group.group_name][dev_name] = DevMonitorView(dev, dev_view)
                    self.addSubInterface(
                        self.monitor[dev_group.group_name][dev_name],
                        QIcon(svg_to_pixmap(dev_view.icon, 600, 600, ColorTheme.light_theme)),
                        dev_name, NavigationItemPosition.SCROLL
                    )
            except TypeError:
                continue




